package ru.ssau.university.persistence.entity;

import java.util.List;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.OneToMany;
import javax.persistence.Table;

@Entity
@Table(name="FACULTY")
public class Faculty extends CommonEntity {
	
	private String title;
	private List<Speciality> specialities;
	private List<Department> departments;
	
	@Column(name="TITLE")
	public String getTitle() {
		return title;
	}

	public void setTitle(String title) {
		this.title = title;
	}

	@OneToMany
    @JoinColumn(name="faculty_id")
	public List<Speciality> getSpecialities() {
		return specialities;
	}

	public void setSpecialities(List<Speciality> specialities) {
		this.specialities = specialities;
	}

	@OneToMany
    @JoinColumn(name="department_id")
	public List<Department> getDepartments() {
		return departments;
	}

	public void setDepartments(List<Department> departments) {
		this.departments = departments;
	}
	
	public String toString() {
		return title;
	}
	
	public boolean equals(Object obj) {
		if (obj instanceof Faculty) {
			Faculty compareTo = (Faculty) obj; 
			Long compareId = compareTo.getId();
			System.out.println("compare: " + compareId + "; id: " + id);
			return compareId.equals(id);
		} else {
			return false;
		}
	}
	
	public int hashCode() {
		return id.intValue();
	}
	
}
